package ch.exm.storm.functional.functions;

public class Summer implements Aggregator<Number> {

	public Number aggregate(Number first, Number second) {
		if (second instanceof Integer) return aggregate(first, (Integer)second);
		if (second instanceof Long) return aggregate(first, (Long)second);
		if (second instanceof Float) return aggregate(first, (Float)second);
		return first.doubleValue() + second.doubleValue();
	}

	public Integer aggregate(Number first, Integer second) {
		return first.intValue() + second.intValue();
	}

	public Long aggregate(Number first, Long second) {
		return first.longValue() + second.longValue();
	}

	public Float aggregate(Number first, Float second) {
		return first.floatValue() + second.floatValue();
	}

	public Number emptyItem() {
		return 0.0;
	}
}
